﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bussiness;
using System.IO;

namespace Presentation {
    public partial class frmThanhLyHopDong : Form {        
        private DataTable _tblContracts;

        public frmThanhLyHopDong() {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e) {
            String contractID = this.txtSearch.Text.Trim();
            ContractBussiness buss = new ContractBussiness();
            this._tblContracts = buss.getContract1(contractID);

            grvContracts.DataSource = this._tblContracts;
        }

        private void button1_Click(object sender, EventArgs e) {
            String contractID = grvContracts.CurrentRow.Cells[0].Value.ToString();
            String id = RandomString(10);
            String info = textBox1.Text;

            ContractBussiness buss = new ContractBussiness();
            buss.updateContract2(contractID);
            buss.liquidateContract(id, contractID, info);

            MessageBox.Show("Thanh ly thanh cong");
        }

        private readonly Random _rng = new Random();
        private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        private string RandomString(int size) {
            char[] buffer = new char[size];

            for (int i = 0; i < size; i++) {
                buffer[i] = _chars[_rng.Next(_chars.Length)];
            }
            return new string(buffer);
        }
    }
}
